<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="padding-top: 30px">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-row>
          <el-form-item prop="consigneeName" label="收货人：">
            <el-input v-model="filters.consigneeName" placeholder="收货人"></el-input>
          </el-form-item>
          <el-form-item prop="phone" label="收货电话：">
            <el-input v-model="filters.phone" placeholder="收货电话"></el-input>
          </el-form-item>
        </el-row>
        <el-row class="search-button">
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button :label="$t('action.reset')" type="primary" @click="resetForm('filters')"/>
          </el-form-item>
          <el-form-item style="float:right">
            <el-button-group>
              <el-tooltip content="刷新" placement="top">
                <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
              </el-tooltip>
              <el-tooltip content="列显示" placement="top">
                <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
              </el-tooltip>
              <el-tooltip content="导出" placement="top">
                <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
              </el-tooltip>
            </el-button-group>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <jic-table
      :height="350"
      v-loading="loading"
      :data="pageResult"
      :columns="filterColumns"
      :showEditOperation="false"
      :showBatchDelete="false"
      :showOperation="false"
      :showSelection="false"
      @findPage="findPage"
      ref="JicTable"
    ></jic-table>
  </div>
</template>

<script>
  import JicTable from "@/views/Core/JicTable";
  import KtButton from "@/views/Core/KtButton";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
  import { exportExcel } from "@/utils/excel";
  export default {
    components: {
      JicTable,
      KtButton,
      TableColumnFilterDialog
    },
    data() {
      return {
        loading:false,
        size: "small",
        provinceList: [],
        cityList: [],
        countryidList: [],
        telephoneList: [],
        restaurants: [],
        filters: {
          phone: "",
          consigneeName: ""
        },
        columns: [
          {prop: "id", label: "序号", minWidth: 50},
          {prop: "consigneeName", label: "收货人", minWidth: 80},
          {prop: "phone", label: "收货电话", minWidth: 80},
          {prop: "addressProvinceId", label: "省", minWidth: 100},
          {prop: "addressCityId", label: "市", minWidth: 100},
          {prop: "addressRegionId", label: "区/县", minWidth: 100},
          {prop: "addressDetail", label: "收货地址", minWidth: 120},
          {prop: "isDefault", label: "是否为默认地址", minWidth: 100,formatter: this.showIsDefault},
          {prop: "createTime", label: "创建时间", minWidth: 120}
        ],
        filterColumns: [],
        pageRequest: {pageNum: 1, pageSize: 10},
        pageResult: {},
        operation: false, // true:新增, false:编辑
        editDialogVisible: false, // 新增编辑界面是否显示
        editLoading: false,
        dataForm: {}
      };
    },
    methods: {
      // 获取分页数据
      findPage: function (data) {
         let this_ = this;
        if (this_.filters == undefined || this_.filters == null) {
          this_.filters = {};
        }
        if(data != null && data.start != null){
          if(data.start != null){
            this.pageRequest.pageNum = data.start;
          }
          if(data.limit != null){
            this.pageRequest.pageSize = data.limit;
          }
        }
        this_.filters.start = this.pageRequest.pageNum;
        this_.filters.limit = this.pageRequest.pageSize;
        this.loading = true;
        this.utils.request.queryRecipientInformationList(this_.filters, function (res) {
          if (res.data.rows == null) {
            res.data.rows = [];
          }
          this_.$refs.JicTable.findPage({content:res.data.rows,total:res.data.total});
          this_.loading = false
        });
      },
      //解析字段
      showIsDefault(row, column, cellValue, index) {
        if (row.isDefault=='0') {
          return '非默认';
        }else if(row.isDefault=='1') {
          return '默认';
        }
      },
      //重置方法
      resetForm(formName) {
        if (this.$refs[formName] != undefined) {
          this.$refs[formName].resetFields();
          this.findPage(null);
        }
      },
      // 处理表格列过滤显示
      displayFilterColumnsDialog: function () {
        this.$refs.tableColumnFilterDialog.setDialogVisible(true);
      },
      // 处理表格列过滤显示
      handleFilterColumns: function (data) {
        this.filterColumns = data.filterColumns;
        this.$refs.tableColumnFilterDialog.setDialogVisible(false);
      },
      // 处理表格列过滤显示
      initColumns: function () {
        var temp = [];
        $.each(this.columns, function (key, val) {
          temp.push(val);
        });
        this.filterColumns = temp;
      },
      //列表下载
      downloadExcel() {
        this.$confirm("确定下载列表文件?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let that = this;
            this.utils.request.queryRecipientInformationList(this.filters, function (res) {
              exportExcel(res.data.rows, that.columns, "会员收货地址");
            });
          })
          .catch(() => {
          });
      }
    },
    mounted() {
      this.initColumns()
    }
  };
</script>

<style lang="scss" scoped>

</style>
